import { getDictionaryList, getUserAllList, getOrgAllList} from '@/views/science/api/common'

const technologyStrength: any = {
  namespaced: true,
  state: {
    rowId: '',

    cxlevelSelect:[], //创新人才团队-团队级别级别-团队类别
    kjlevelSelect:[], //科技领军人才- 人才级别-人才类别

    titleList:[], //称号
    businessList:[], // 技术领域 - 技术标准-业务板块
    tdStatue:[], // 团队状态

    userAllList: [], //全部人员
    orgAllList: [], //全部机构单位

    sexList: [], //性别

    talentTeamInfo: {
      id: '',
      name: '',
      unitName: '',
      unitId: '',
      managerName: '',
      managerId: '',
      managerContract:'',
      teamLevel: '',
      teamLevelId: '',
      teamClass: '',
      teamClassId: '',
      techFieldName: '',
      techFieldId: '',
      confirmDate: '',
      doctorCount: '',
      middleTitleCount: '',
      shortIntroduction: '',

      buildBudget:'',//建设预算
      buildTarget:'',//建设目标
      buildContent:'',//建设内容
      needDeptSuggest:'',//需求部门意见
      undertakeUnitId:'',
      applyUnitName:'',
      applyUnit:'',
      projectName:'',
    },

    tleadershipInfo: {
      id: '',
      userName: '',
      userId: '',
      unitName: '',
      unitId: '',
      talentLevel: '',
      talentLevelId: '',
      talentClass: '',
      talentClassId: '',
      title: '',
      titleId: '',
      confirmDate: '',
      awardUnit: '',
      sex: '',
      birthdar_date: '',
      remark: ''
    },

  },
  mutations: {

    getRowId(state: any, id) {
      state.rowId = id;
    },

    emptytalentTeamInfo(state: any) {
      Object.keys(state.talentTeamInfo).forEach((key) => {
        state.talentTeamInfo[key] = '';
      })
    },

    emptytleadershipInfo(state: any) {
      Object.keys(state.tleadershipInfo).forEach((key) => {
        state.tleadershipInfo[key] = '';
      })
    },



    getTalentTeamInfo(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.talentTeamInfo
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.talentTeamInfo = { ...list };
    },

    gettleadershipInfo(state: any, data) {
      const arr1 = Object.keys(data)
      const list = state.tleadershipInfo
      for (const key in list) {
        if (arr1.indexOf(key) !== -1) {
          list[key] = data[key]
        }
      }
      state.tleadershipInfo = { ...list };
    },
    

    saveDictionaryList(state: any, listData) {
      console.log(listData)

      state.cxlevelSelect = listData.KJSL_CX_LEVEL
      state.kjlevelSelect = listData.KJSL_LJ_LEVEL

      state.tdStatue = listData.KJSL_TEAM_STATUS

      state.stateSelect = listData.KJSL_TALENT_LEVEL
      state.ptRoleList = listData.KJSL_TALENT_CATEGORY

      state.titleList = listData.KJSL_OBTAINING_TITLES
      state.businessList = listData.KJSL_BUSINESS_SECTOR
      state.sexList = listData.SEX
    },

    saveUserAllList(state: any, listData) {
        state.userAllList = listData
      },
  
      saveOrgAllList(state: any, listData) {
        state.orgAllList = listData
      },

  

  },
  actions: {
   
    // 根据字典分类code集合获取字典树
    async getDictionaryList({ commit, state }: any, params) {
      const a = params
      const rst = await getDictionaryList(a)
      // const rst = await getDictByCodeList(a)
      const data = rst.data.data
      commit('saveDictionaryList', { ...data })
    },

     //获取全部人员
     async getUserAllList({ commit, state }: any) {
        const rst = await getUserAllList()
        const data = rst.data.data
        console.log(data)
        commit('saveUserAllList', { ...state.userAllList, ...data })
      },
  
  
      //获取全部机构单位
      async getOrgAllList({ commit, state }: any) {
        const rst = await getOrgAllList()
        const data = rst.data.data
        console.log(rst)
        commit('saveOrgAllList', { ...state.orgAllList, ...data })
      },
  },
}

export default technologyStrength
